package com.smartlifev30.baiwei.view.recyclerViewComponent;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * RecyclerView 基础ViewHolder。默认不做任何处理
 * 仅仅是提供为Item设置长按和单击事件的方法。
 *
 * @author tys
 * @date 2017/10/14
 */

public class BaseViewHolder extends RecyclerView.ViewHolder {
    public BaseViewHolder(View itemView) {
        super(itemView);
    }


    public void setItemClickListen(@Nullable final View itemView, @NonNull final BaseAdapter adapter) {
        if (itemView != null && adapter.mItemClickListen != null) {
            itemView.setOnClickListener(v -> adapter.mItemClickListen.onItemClick(itemView, getAdapterPosition()));
        }

        if (itemView != null && adapter.mLongItemClickListen != null) {
            itemView.setOnLongClickListener(v -> {
                adapter.mLongItemClickListen.onLongItemClick(v, getAdapterPosition());
                return true;
            });
        }

    }

}
